<!-- 预警管理 -->
<template>
  <div class="warningAdmin" v-loading="warningAdminLoading">
    <div class="title">预警管理</div>
    <div class="searchBox">
      <el-form ref="form" :model="searchForm" size="mini" inline>
        <el-row>
          <el-form-item label="预警站点" label-width="90px">
            <el-select
              v-model="searchForm.waterStation"
              placeholder="请选择水站名称"
              @change="changeSelect"
            >
              <p v-for="(item, index) of stationList" :key="index">
                <el-option :label="item" :value="item"></el-option>
              </p>
            </el-select>
          </el-form-item>
          <el-form-item label="预警类型" label-width="90px">
            <el-select
              v-model="searchForm.warningType"
              placeholder="请选择处理状态"
              @change="changeType"
            >
              <p v-for="(item, index) of warningTypes" :key="index">
                <el-option :label="item" :value="item"></el-option>
              </p>
            </el-select>
          </el-form-item>
          <el-form-item label="处理状态" label-width="90px">
            <el-select
              v-model="handleStatus1"
              placeholder="请选择处理状态"
              @change="changeStatus"
            >
              <p v-for="item in handleStatus" :key="item.id">
                <el-option :label="item.name" :value="item.status"></el-option>
              </p>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <p slot="label" class="miniLabel">时间段</p>
            <el-date-picker
              @change="changeTime"
              v-model="timePickerDay"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            ></el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="时间" label-width="60px">
            <el-col :span="11">
              <el-date-picker
                v-model="searchForm.starttime"
                type="date"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择开始日期"
              ></el-date-picker>
            </el-col>
            <el-col :span="2" class="line">-</el-col>
            <el-col :span="11">
              <el-date-picker
                v-model="searchForm.lasttime"
                type="date"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择结束日期"
              ></el-date-picker>
            </el-col>
          </el-form-item>-->
          <el-form-item>
            <el-button
              type="primary"
              class="greenBtn"
              size="mini"
              @click="
                onSubmit({
                  pageSize: pageSize,
                  pageNum: 1,
                  warningStatus: handleStatus1,
                })
              "
              >确定</el-button
            >
            <el-tooltip
              content="批量处理只能选同一种预警类型并且时间间隔不超过6个小时"
              placement="bottom"
              effect="light"
            >
              <el-button
                type="primary"
                class="greenBtn"
                size="mini"
                v-show="
                  !userInfo.roles.includes('manager') &&
                  !userInfo.roles.includes('environmentalDirector')
                "
                @click="changeBatchHandle(!isBatchHandle)"
                >{{ isBatchHandle ? "关闭" : "开启" }}批量处理</el-button
              >
            </el-tooltip>
            <el-button
              type="success"
              size="mini"
              v-show="isBatchHandle"
              @click="batchHandle"
              >批量处理</el-button
            >
            <!-- <el-button size="mini" >导出</el-button> -->
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="tableBox">
      <el-table
        :data="warningAdmin.data"
        border
        size="mini"
        ref="warningTable"
        style="width: 100%"
        :header-cell-style="{ color: '#666', backgroundColor: '#feedcf' }"
        :row-style="checkCanSelect"
        @selection-change="selectionChange"
        @select-all="selectAll"
        :select-on-indeterminate="false"
        :default-sort="{ prop: 'warningTime', order: 'descending' }"
      >
        <el-table-column
          v-if="isBatchHandle"
          type="selection"
          :selectable="checkSelectable"
          align="center"
          width="40"
        ></el-table-column>
        <el-table-column
          prop="warningId"
          label="编号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="warningTime"
          label="预警时间"
          sortable
          align="center"
        ></el-table-column>
        <el-table-column
          prop="warningType"
          label="预警类型"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="warningStation"
          label="预警站点"
          align="center"
        ></el-table-column>

        <el-table-column prop="warningContent" label="预警内容" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              class="openDetailBtn"
              @click="openDetail(scope.row.warningId)"
              >查看</el-button
            >
          </template>
        </el-table-column>

        <!-- v-if="!userInfo.roles.includes('manager')" -->
        <el-table-column prop="warningStatus" label="处理状态" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="text" v-if="scope.row.warningStatus == 3 && userInfo.roles.includes('manager')" @click="openIsHandled(scope.row.warningId,scope.row)">已处理</el-button> -->
            <span
              v-if="scope.row.warningStatus == 0"
              type="text"
              :class="[
                'dangerText1',
                scope.row.warningStatus == 2 ? 'lan' : '',
              ]"
              @click="added(scope.row.warningId, scope.row.warningStatus)"
              >{{ warningStatus[scope.row.warningStatus] }}</span
            >
            <button
              v-else
              type="text"
              :class="['dangerText', scope.row.warningStatus == 2 ? 'lan' : '']"
              @click="added(scope.row.warningId, scope.row.warningStatus)"
            >
              {{ warningStatus[scope.row.warningStatus] }}
            </button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <v-paging
      :pageNum="currentPage"
      @setCurrent="setNum"
      @setCurren="setPage"
      :total="warningAdmin.total"
    />

    <!-- 预警内容 -->
    <el-dialog :visible.sync="warnCntVisible" append-to-body>
      <div slot="title">
        <p>预警内容</p>
      </div>
      <h3 style="margin-bottom: 12px">
        {{ curWarnCntDetail.warningTime }}
        {{ curWarnCntDetail.warningStation }}
      </h3>
      <div v-if="curWarnCntDetail.warningType === '因子超标预警'">
        <el-table :data="curWarnCntDetail.content" border show-header>
          <el-table-column prop="name" label="因子名称" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.value.factor }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="标准值" align="center">
            <template slot-scope="scope">
              <span
                >{{ scope.row.value.standardLimit
                }}{{
                  indexOFShowUnit(scope.row.value.factor) ? "mg / L" : ""
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="value" label="预警值" align="center">
            <template slot-scope="scope">
              <span
                >{{ scope.row.value.standard
                }}{{
                  indexOFShowUnit(scope.row.value.factor) ? "mg / L" : ""
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="value" label="监测值" align="center">
            <template slot-scope="scope">
              <span style="color: #e53139"
                >{{ scope.row.value.realConc }}
                {{
                  indexOFShowUnit(scope.row.value.factor) ? "mg / L" : ""
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="value" label="超标倍数" align="center">
            <template slot-scope="scope">
              <span style="color: #e53139">{{
                scope.row.value.excessiveMultiple
              }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="curWarnCntDetail.warningType === '分钟数据预警'">
        <el-table :data="curWarnCntDetail.content" border show-header>
          <el-table-column prop="name" label="因子名称" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.value.factor }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="标准值" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.value.factor === 'pH'">
                {{ scope.row.value.standardLimit
                }}{{ indexOFShowUnit(scope.row.value.factor) ? "mg / L" : "" }}
              </span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="预警值" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.value.factor === 'pH'">
                {{ scope.row.value.standard
                }}{{ indexOFShowUnit(scope.row.value.factor) ? "mg / L" : "" }}
              </span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="监测值" align="center">
            <template slot-scope="scope">
              <span style="color: #e53139"
                >{{ scope.row.value.realConc }}
                {{
                  indexOFShowUnit(scope.row.value.factor) ? "mg / L" : ""
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="value" label="超标倍数" align="center">
            <template slot-scope="scope">
              <span style="color: #e53139">{{
                scope.row.value.excessiveMultiple
              }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="curWarnCntDetail.warningType === '设备异常预警'">
        <el-table :data="curWarnCntDetail.content" border :show-header="false">
          <el-table-column prop="name" label="超标因子" align="center">
            <template slot-scope="scope">
              <span>{{ common.translate(scope.row.name) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="超标值" align="center">
            <template slot-scope="scope">
              <span style="color: #e53139"
                >{{ scope.row.value || "异常" }}
                {{
                  indexOFShowUnit(common.translate(scope.row.name))
                    ? "mg / L"
                    : ""
                }}</span
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="curWarnCntDetail.warningType === '设备离线'">
        <p
          class="missWarning"
          v-for="item in curWarnCntDetail.content"
          :key="item.name"
        >
          {{ common.translate(item.name) }} :
          <span style="color: #e53139">{{ item.value }}</span>
        </p>
      </div>
      <p class="responseCnt">
        <!-- v-show="!userInfo.roles.includes('manager')" -->
        <el-button
          size="small"
          @click="responseWarning(curWarnCntDetail.warningId)"
          >响应并处理</el-button
        >
      </p>
    </el-dialog>

    <!-- 待审核 -->
    <el-dialog
      width="40%"
      :visible.sync="isHandledVisible"
      custom-class="warningAdmin"
      append-to-body
    >
      <div slot="title">
        <p>待审核</p>
      </div>
      <el-form
        :model="curIsHandledDetail"
        size="mini"
        label-width="100px"
        ref="updateForm1"
      >
        <el-form-item label="处理描述">
          <el-input
            type="textarea"
            :rows="4"
            v-model="curIsHandledDetail.processingMark"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item
          label="现场图片"
          label-width="100px"
          style="margin-top: 15px"
        >
          <viewer :images="curIsHandledDetail.imgList">
            <img
              class="imgItem"
              v-for="(item, index) of curIsHandledDetail.imgList"
              :key="index"
              :src="'http://47.112.16.168:' + item"
            />
            <!-- <img
              class="imgItem"
              v-for="(item, index) of curIsHandledDetail.imgList"
              :key="index"
              :src="'http://134.175.122.199:8888' + (item.substr(4))"
            />-->
          </viewer>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理人">
              <el-input
                v-model="curIsHandledDetail.processingPerson"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-form-item label="处理时间">
          <el-input
            v-model="curIsHandledDetail.gmtModified"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            class="greenBtn btn"
            size="mini"
            @click="subActions"
            :disabled="false"
            >审核通过</el-button
          >
          <el-button
            type="primary"
            class="greenBtn btn"
            size="mini"
            @click="rejectClose"
            :disabled="false"
            >审核驳回</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 正在处理 -->
    <el-dialog
      width="40%"
      :visible.sync="updateFormVisible"
      @close="clearUpdateForm"
      append-to-body
    >
      <div slot="title">
        <p>{{ isBatchHandle ? "批量" : "" }}处理</p>
      </div>
      <el-form
        :model="updateForm"
        :rules="updateFormRules"
        size="mini"
        label-width="100px"
        ref="updateForm2"
        v-loading="updateFormLoading"
      >
        <el-form-item label="处理描述" prop="processingMark">
          <el-input
            type="textarea"
            :rows="4"
            v-model="updateForm.processingMark"
            placeholder="请填写处理描述"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="现场图片"
          label-width="100px"
          style="margin-top: 15px"
          prop="photoFiles"
        >
          <el-upload
            ref="addUploadPhoto"
            action
            :file-list="updateForm.photoFiles"
            list-type="picture-card"
            multiple
            :limit="4"
            :on-change="uploadChange"
            :on-exceed="uploadExceed"
            :http-request="handleSubmit"
            :auto-upload="false"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理人" prop="processingPerson">
              <el-input
                v-model="updateForm.processingPerson"
                placeholder="请填写处理人"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-form-item>
          <el-button
            type="primary"
            class="greenBtn"
            size="mini"
            @click="addedSubmit('updateForm2')"
            >确定</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 已处理 -->
    <el-dialog
      width="40%"
      :visible.sync="processedStatus"
      custom-class="warningAdmin"
      append-to-body
    >
      <div slot="title">
        <p>处理结果</p>
      </div>
      <el-form
        :model="curIsHandledDetail"
        size="mini"
        label-width="100px"
        ref="updateForm1"
      >
        <el-form-item label="处理描述">
          <el-input
            type="textarea"
            :rows="4"
            v-model="curIsHandledDetail.processingMark"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item
          label="现场图片"
          label-width="100px"
          style="margin-top: 15px"
        >
          <viewer :images="curIsHandledDetail.imgList">
            <img
              class="imgItem"
              v-for="(item, index) of curIsHandledDetail.imgList"
              :key="index"
              :src="'http://47.112.16.168:' + item"
            />
            <!-- <img
              class="imgItem"
              v-for="(item, index) of curIsHandledDetail.imgList"
              :key="index"
              :src="'http://134.175.122.199:8888' + (item.substr(4))"
            />-->
          </viewer>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理人">
              <el-input
                v-model="curIsHandledDetail.processingPerson"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-form-item label="处理时间">
          <el-input
            v-model="curIsHandledDetail.gmtModified"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 审核驳回 -->
    <el-dialog
      width="40%"
      :visible.sync="reject"
      @close="clearUpdateForm"
      append-to-body
    >
      <div slot="title">
        <p>审核驳回</p>
      </div>
      <el-form size="mini" label-width="100px">
        <el-form-item label="*驳回原因">
          <el-input
            type="textarea"
            :rows="4"
            v-model="rejectText"
            maxlength="20"
            show-word-limit
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="rejectExamine"
            >确定</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import posts from "@/plugins/request";
import { mapActions, mapGetters, mapMutations } from "vuex";
import common from "@/plugins/common";
import standard from "@/plugins/standard";
import { auditAction, rejectionAction } from "@/http/api";
export default {
  name: "warningAdmin",
  data() {
    return {
      Clickable: false, //处理状态是否可点击
      reject: false, //审核驳回弹窗
      id: "", //列表id
      ProcessingResults2: false,
      ProcessingResults: false, //处理结果
      processedStatus: false, //已处理
      rejectText: "", //驳回原因
      text: null,
      currentPage: 1, //页数
      pageSize: 12, //条数
      warningAdminLoading: false,
      receUserLoading: false,
      searchForm: {
        waterStation: "",
        warningType: "",
        starttime: "",
        lasttime: "",
      },
      updateFormVisible: false,
      addFormData: {},
      updateFormLoading: false,
      updateForm: {
        warningId: "",
        processingMark: "",
        processingPerson: "",
        photoFiles: [],
      },
      timePickerDay: [],
      updateFormRules: {
        processingMark: [
          { required: true, message: "请输入处理描述", trigger: "blur" },
        ],
        processingPerson: [
          { required: true, message: "请输入处理人", trigger: "blur" },
        ],
        photoFiles: [
          { required: true, message: "请选择照片", trigger: "change" },
        ],
      },
      handleStatus1: "",
      handleStatus: [
        //处理状态
        {
          name: "待响应",
          status: 0,
          id: 1,
        },
        {
          name: "待处理",
          status: 1,
          id: 3,
        },
        {
          name: "待审核",
          status: 3,
          id: 4,
        },
        {
          name: "已处理",
          status: 2,
          id: 2,
        },
      ],
      warnCntVisible: false,
      curWarnCntDetail: {
        warningId: "",
        warningStation: "",
        warningTime: "",
        content: [],
      },
      isHandledVisible: false,
      curIsHandledDetail: {
        reject: "",
      },
      status: 0,
      warningStatus: {
        0: "待响应",
        1: "待处理",
        2: "已处理",
        3: "待审核",
      },
      warningTypes: [],
      isBatchHandle: false, //是否是批量处理模式
      multipleSelection: [],
      common,
      standard,
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() > Date.now();
        },
      },
    };
  },
  async created() {
    await this.getStationListName({ dataType: null });
    this.timePickerDay = [
      common.changeDateToString(new Date(new Date().getTime() - 2592000000)),
      common.changeDateToString(new Date()),
    ];
    this.warningTypes = await posts.fetchWarningTypes(); //预警类型

    this.searchForm.warningType = this.warningTypes[0];
    if ("waterStation" in this.$route.query) {
      this.searchForm.waterStation = this.$route.query.waterStation;
    }
    if ("warningType" in this.$route.query) {
      this.searchForm.warningType = this.$route.query.warningType;
    }
    this.onSubmit();
  },
  computed: {
    ...mapGetters({
      stationList: "getStationList",
      warningAdmin: "getWarningAdmin",
      userInfo: "getUserInfo",
    }),
  },
  methods: {
    ...mapActions([
      "getStationListName",
      "fetchWarningAdminList",
      "updateWarningAdmin",
      "updateWarningAdminBatch",
      "responseWarningAdmin",
    ]),
    ...mapMutations(["changePageNum"]),
    changeSelect() {
      this.currentPage = 1;
      this.onSubmit();
    },
    changeType() {
      this.currentPage = 1;
      this.onSubmit();
    },
    changeStatus() {
      this.currentPage = 1;
      this.onSubmit();
    },
    changeTime() {
      this.currentPage = 1;
      this.onSubmit();
    },
    async onSubmit(
      pageOption = {
        pageSize: this.pageSize,
        pageNum: this.currentPage,
        warningStatus: this.handleStatus1,
      }
    ) {
      this.warningAdminLoading = true;
      this.searchForm.starttime = this.timePickerDay[0];
      this.searchForm.lasttime = this.timePickerDay[1];
      await this.fetchWarningAdminList({ ...this.searchForm, ...pageOption });
      this.warningAdminLoading = false;
    },
    //处理状态事件
    added(id, id2) {
      this.updateForm.warningId = id;
      this.updateForm.processingPerson = this.userInfo.user.username;
      switch (id2) {
        case 1: //正在处理
          this.updateFormVisible = true;
          break;
        case 2: //已处理
          this.processedStatus = true;
          this.openIsHandled(id);
          break;
        case 3: //待审核
          if (this.userInfo.roles.includes("manager")) return;
          this.isHandledVisible = true;
          this.openIsHandled(id);
          break;
      }
    },
    pageUpdate(option) {
      this.onSubmit(option);
    },
    //响应并处理
    async responseWarning(id) {
      this.status = 1;
      this.id = id;
      this.warnCntVisible = false;
      let result = await this.responseWarningAdmin({ id });
      if (result.message !== "success") {
        this.$notify({
          type: "warning",
          title: "提示",
          message: result.info,
        });
      } else {
        this.$notify({
          type: "success",
          title: "成功",
          message: "预警已响应，请尽快上传完成处理并提交处理结果！",
        });
        this.onSubmit();
      }
    },
    //确定审核通过2
    subActions() {
      auditAction({ warningId: this.id }).then((res) => {
        this.$notify({
          type: "success",
          title: "成功",
          message: res.info,
        });
        this.onSubmit();
        this.isHandledVisible = false;
      });
    },
    //审核通过
    async addedSubmit(id) {
      this.$refs[id].validate(async (valid) => {
        if (valid) {
          if (this.updateForm.photoFiles.length > 0) {
            this.updateFormLoading = true;
            this.addFormData = new FormData();
            let updateForm = this.updateForm;
            this.$refs.addUploadPhoto.submit();
            for (let i in updateForm) {
              this.loopAppend(this.addFormData, i, updateForm[i]);
            }
            let result = {};
            // 用isBatchHandle判断是否为批量处理模式
            if (this.isBatchHandle) {
              //批量处理模式
              this.addFormData.append(
                "warningIdList",
                this.findNoHandel(this.multipleSelection)
              );
              result = await this.updateWarningAdminBatch(this.addFormData);
            } else {
              //单条处理模式
              result = await this.updateWarningAdmin(this.addFormData);
            }
            if (result.message !== "success") {
              this.$notify({
                type: "warning",
                title: "提示",
                message: result.info,
              });
            } else {
              this.$notify({
                type: "success",
                title: "成功",
                message: result.info,
              });
              this.$refs[id].resetFields();
              this.updateFormVisible = false;
              this.changeBatchHandle(false);
              this.changePageNum(1);
              this.onSubmit();
            }
            this.updateFormLoading = false;
          } else {
            this.$notify.warning({
              title: "警告",
              message: "最少上传1张图片",
            });
          }
        } else {
          return false;
        }
        this.ProcessingResults = true;
      });
    },
    //确定驳回
    rejectExamine() {
      rejectionAction({
        warningId: this.id,
        rejectionReason: this.rejectText,
      }).then((res) => {
        this.reject = false;
        this.$notify({
          type: "success",
          title: "成功",
          message: res.info,
        });
      });
    },
    //点击驳回
    rejectClose() {
      this.reject = true;
      this.isHandledVisible = false;
    },
    //设置页数
    setPage(val) {
      this.currentPage = val;
      this.onSubmit();
    },
    //设置条数
    setNum(val) {
      this.pageSize = val;
      this.onSubmit();
    },
    uploadChange(file, fileList) {
      this.updateForm.photoFiles = fileList;
    },
    uploadExceed() {
      this.$notify.warning({
        title: "警告",
        message: "最多上传4张图片",
      });
    },
    handleSubmit(response) {
      this.addFormData.append("files", response.file);
    },
    loopAppend(formData, key, value) {
      formData.append(key, value);
    },
    //预警内容弹窗
    openDetail(id) {
      let curWarning = this.warningAdmin.data.find((v) => v.warningId === id);
      this.curWarnCntDetail.warningStation = curWarning.warningStation;
      this.curWarnCntDetail.warningTime = curWarning.warningTime;
      this.curWarnCntDetail.warningType = curWarning.warningType;
      this.curWarnCntDetail.warningId = id;
      this.curWarnCntDetail.content = [];
      let curContent = curWarning.warningContent;
      for (let i in curContent) {
        this.curWarnCntDetail.content.push({
          name: i,
          value: curContent[i] * 1 ? curContent[i] * 1 : curContent[i],
        });
      }
      this.warnCntVisible = true;
    },
    //处理中
    openIsHandled(id, id2) {
      this.id = id;
      this.curIsHandledDetail = this.warningAdmin.data.find(
        (v) => v.warningId === id
      );
      let imgList = [];
      if (this.curIsHandledDetail.livePhoto) {
        imgList = this.curIsHandledDetail.livePhoto.split(",");
        imgList.pop();
      }
      this.curIsHandledDetail.imgList = imgList.length ? imgList : [];
    },
    indexOFShowUnit(val) {
      let map = [
        "pH",
        "总镍监测设备",
        "总铬监测设备",
        "总氮监测设备",
        "总磷监测设备",
        "总铜监测设备",
        "总氰化物监测设备",
        "氨氮监测设备",
        "pH监测设备",
        "设备异常",
        "总镍设备告警",
        "总铬设备告警",
        "总氮设备告警",
        "总磷设备告警",
        "总铜设备告警",
        "总氰化物设备告警",
        "氨氮设备告警",
        "pH设备告警",
        "系统设备告警",
        "COD设备告警",
        "总锌设备告警",
      ];
      return !map.includes(val);
    },
    clearUpdateForm() {
      this.$refs.updateForm.resetFields();
    },
    changeBatchHandle(flag) {
      //修改批量处理模式
      this.isBatchHandle = flag;
      if (!flag) this.toggleSelection();
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.warningTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.warningTable.clearSelection();
      }
    },
    checkSelectable(row) {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length > 0) {
        let firstWarning = this.warningAdmin.data.find(
          (v) => v.warningId === multipleSelection[0]
        );
        return (
          row.warningType === firstWarning.warningType &&
          Math.abs(
            new Date(row.warningTime).getTime() -
              new Date(firstWarning.warningTime).getTime()
          ) <=
            1000 * 60 * 60 * 6
        );
      }
      return true;
    },
    selectAll(selection) {
      let arr = [];
      for (let i = 0; i < selection.length; i++) {
        if (this.checkSelectable(selection[i])) {
          arr.push(selection[i]);
        }
      }
      this.toggleSelection();
      this.toggleSelection(arr);
    },
    selectionChange(val) {
      this.multipleSelection = val.map((v) => v.warningId);
    },
    checkCanSelect({ row }) {
      return this.checkSelectable(row)
        ? { "background-color": "#fff" }
        : { "background-color": "#f5f7fa" };
    },
    batchHandle() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length < 1) {
        this.$notify({
          type: "warning",
          message: "请选择可处理的预警！",
          title: "提醒",
        });
        return;
      }
      this.changeBatchHandle(true);
      this.updateForm.processingPerson = this.userInfo.user.username;
      this.updateFormVisible = true;
    },
    findNoHandel(multipleSelection) {
      let result = [];
      for (let i = 0; i < multipleSelection.length; i++) {
        let curWarning = this.warningAdmin.data.find(
          (v) => v.warningId === multipleSelection[i]
        );
        if (curWarning.warningStatus < 2) {
          result.push(curWarning.warningId);
        }
      }
      return result;
    },
  },
};
</script>
<style scoped lang="scss" scoped>
.warningAdmin {
  background: #fff;
  min-height: 100%;
  padding: 0 20px 0 20px;
  .title {
    position: relative;
    left: 15px;
    line-height: 70px;
    font-size: 16px;
  }
}
.warningAdmin .title::before {
  content: "";
  position: absolute;
  left: -15px;
  width: 4px;
  height: 20px;
  top: 25px;
  background-color: #2399ff;
}
.searchBox {
  background: #fff;
  margin-bottom: 15px;
}
.searchBox .line {
  text-align: center;
}
.warningAdmin .imgItem {
  max-width: 200px;
  margin-right: 15px;
}
.responseCnt {
  width: 100%;
  padding-top: 20px;
  overflow: hidden;
}
.responseCnt button {
  float: right;
}
.missWarning {
  line-height: 26px;
  font-size: 16px;
}
.openDetailBtn:visited {
  color: red;
}
.searchBox {
  /deep/ .el-form-item__label {
    text-align: left;
    padding-left: 14px;
  }
}
</style>
<style>
.dangerText {
  color: #e53139;
  opacity: 0.5;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
}
.dangerText1 {
  color: #e53139;
  opacity: 0.5;
  font-size: 14px;
}
.lan {
  color: #87cefa !important;
}
.dangerText.el-button--text:focus,
.dangerText.el-button--text:hover {
  color: #ff9393;
  border-color: transparent;
  background-color: transparent;
}
.el-table-column--selection .cell {
  padding-right: 10px;
}
</style>

